package com.xf.leecode.linked;

import com.xf.leecode.bean.linked.ListNode;

import java.util.LinkedList;
import java.util.List;

/**
 * @author zouxf Department:3cs
 * @date 2022/7/25 21:29
 * @description
 * @see
 */
public class ReverseLinked {
    public static void main(String[] args) {
        LinkedList linkedList = new LinkedList();
        linkedList.add("x");
        ListNode head = new ListNode();
        ListNode pre = head;
        for (int i = 0; i < 10; i++) {
            pre.next = new ListNode();
            pre.val = i;
            pre = pre.next;
        }
        System.out.println(reverseList(head,2,6));
    }


    public static ListNode reverseList(ListNode head,int m,int n) {
        ListNode res = new ListNode(-1);
        res.next = head;
        ListNode pre = res;
        ListNode cur = head;
        for (int i = 0; i < m; i++) {
            pre = cur;
            cur = cur.next;
        }
        System.out.println("curr:"+cur);
        System.out.println("pre:"+pre);
        for (int i = m; i < n; i++) {
            ListNode tmp = cur.next;
            cur.next = tmp.next;
            tmp.next = pre.next;
            pre.next = tmp;
        }
        return res.next;

    }
    public ListNode ReverseList(ListNode head) {
        if (null == head) {
            return null;
        }
        ListNode curr = head;
        ListNode pre = null;
        while (curr != null) {
            System.out.println("---");
            ListNode temp = curr.next;
            curr.next = pre;
            pre = curr;
            curr = temp;
        }
        return pre;

    }
}


